﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.ServiceModel.Channels;
using OnlineGameLibrary.ClientChannel;

namespace OnlineGameLibrary.Activities
{

    public sealed class ClientChannelBroadcastSend : NativeActivity
    {
        [RequiredArgument]
        public InArgument<Message> Message { get; set; }

        [RequiredArgument]
        public InArgument<IList<IMyClientChannel>> ClientChannels { set; get; }

        protected override void Execute(NativeActivityContext context)
        {
            var msg = Message.Get(context);
            var channels = ClientChannels.Get(context);
            var buffer = msg.CreateBufferedCopy(channels.Count);
            
            foreach (var channel in channels)
            {
                channel.SendMessageToPlayer(buffer.CreateMessage());
            }
        }
    }
}
